﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppManagement.LoadingManagers
{
    public class Loading
    {
        private delegate void TimeTask();
        private static IAsyncResult result;
        private static TimeTask ASynInvoke;
        public static FrmLoading waiting;
        private delegate void LoadingDel();

        public static void PreLoading()
        {
            ASynInvoke = new TimeTask(WaitLoad);
            result = ASynInvoke.BeginInvoke(null, null);
        }

        public static void PosLoading()
        {
            if (waiting.InvokeRequired)
            {
                LoadingDel del = new LoadingDel(PosLoading);
                waiting.Invoke(del, new object[] { });
            }
            if (waiting != null)
            {
                waiting.Close();
                waiting = null;
            }
        }

        public static void WaitLoad()
        {
            if (waiting == null)
            {
                waiting = new FrmLoading("Đang thực hiện");
            }
            if (waiting.InvokeRequired)
            {
                LoadingDel del = new LoadingDel(WaitLoad);
                waiting.Invoke(del, new object[] { });
            }
            waiting.ShowDialog();
        }
    }
}
